package com.samebuilding.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.samebuilding.dao.GiftRecordDAO;
import com.samebuilding.domain.GiftRecord;

public class GiftRecordDAOImpl extends HibernateDaoSupport implements
		GiftRecordDAO {

	public GiftRecord findById(String id) {
		List list=this.getHibernateTemplate().find("from GiftRecord as gr where gr.id=?",id);
		if(list!=null&&list.size()>0){
			return (GiftRecord) list.get(0);
		}
		return null;
	}

	public void save(GiftRecord gr) {
		this.getHibernateTemplate().save(gr);

	}

	public void update(GiftRecord gr) {
		this.getHibernateTemplate().update(gr);

	}

	public List findRecived(int userNo) {
		
		return this.getHibernateTemplate().find("from GiftRecord as gr,Gift as gf where gr.giftCode=gf.code and gr.receiveUserNo=?",userNo);
	}

	public List findSend(int userNo) {
		// TODO Auto-generated method stub
		return this.getHibernateTemplate().find("from GiftRecord as gr,Gift as gf where gr.giftCode=gf.code and gr.senderUserNo=?",userNo);
	}

}
